﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using hedefgrup.reports.renault.database;
using System.Data;
using System.Globalization;

public partial class adm_dataremoval : reportPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.initialize();
        base.ensureAdministratorIsLoggedIn();

        DataTable top1Data = db.query("SELECT TOP 1 YIL, AY FROM " + base.getDataCache().dataTableName + " ORDER BY YIL DESC, AY DESC");
        int year = Convert.ToInt32(top1Data.Rows[0]["YIL"]);
        int month = Convert.ToInt32(top1Data.Rows[0]["AY"]);

        if (Request.QueryString["CONFIRM"] == "YES")
        {
            long deletedRows = db.execute("DELETE FROM " + base.getDataCache().dataTableName + " WHERE YIL = @p_0 AND AY = @p_1", year, month);
            long deletedVerbatims = db.execute("DELETE FROM " + "renault_verbatim" + " WHERE YIL = @p_0 AND AY = @p_1 AND project = @p_2", year, month, base.userProjectName.ToUpperInvariant());
            message.Text = year + " " + DateTimeFormatInfo.CurrentInfo.GetMonthName(month) + " verileri (" + deletedRows + " kayıt) ve verbatim kayıtları (" + deletedVerbatims + " kayıt) silinmiştir.";
        }
        else
        {
            DataTable countOfRowsToRemoveData = db.query("SELECT COUNT(*) FROM " + base.getDataCache().dataTableName + " WHERE YIL = @p_0 AND AY = @p_1", year, month);
            int countOfRowsToRemove = Convert.ToInt32(countOfRowsToRemoveData.Rows[0][0]);
            message.Text = year + " " + DateTimeFormatInfo.CurrentInfo.GetMonthName(month) + " verileri silinecektir. (" + countOfRowsToRemove + " Kayıt) Onaylıyor musunuz?";
            yesConfirm.Visible = noCancel.Visible = true;
        }
    }
}